package com.qf.homework.service.impl;

import com.qf.homework.dao.UserDao;
import com.qf.homework.dao.impl.UserDaoImpl;
import com.qf.homework.entity.User;
import com.qf.homework.service.UserService;

import java.sql.SQLException;

public class UserServiceImpl implements UserService {
    private UserDao userDao=new UserDaoImpl();
    @Override
    public User login(String username, String password) throws SQLException {
        User user = userDao.getUserByUsername(username);
        User usr=null;
        if (user.getPassword().equals(password)){usr= user;}
        return usr;
    }

    @Override
    public int register(String username, String password) throws SQLException {
        int res=0;
        if (userDao.getUserByUsername(username)==null) {
            res=userDao.register( username,  password);
        }
        return res;
    }
}
